/*
调用组件封装
*/
function request({url, data, method="GET", contenType=1}) {
	let header = {
		'content-type': contenType === 1 ? 'application/json' : 'application/x-www-form-urlencoded',
		'platform': 'app'
	}
	
	let type = uni.getSystemInfoSync().uniPlatform;
	let baseUrl = '';
	if(type == 'web') {
		baseUrl = "/api/dataAPI";
	}else baseUrl = "https://data.ahyzg.com/api/dataAPI";
	return new Promise((resolve, reject) => {
		uni.request({
			url:baseUrl + url,
			data,
			method,
			header,
			success:res => {
				if(res.statusCode === 200) {
					resolve(res.data)
				} else if(res.statusCode === 401) {
					uni.showToast({
						icon:'none',
						title:'未登录或登录状态已关闭',
						duration:1500
					});
				} else if(res.statusCode === 405) {
					uni.showToast({
						icon:'none',
						title:'请求方法错误',
						duration:1500
					});
				} else {
					uni.showToast({
						icon:'none',
						title:'请求错误' + res.statusCode,
						duration:1500
					});
				}
			},
			fail: (err) => {
				uni.showToast({
					icon:'none',
					title:err.errMsg,
					duration:1500
				});
				reject(err)
			}
		})
	})
}

export default { request }